package org.jash.mvp2206.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SPUtils {
    private SharedPreferences sp;
    private SPUtils() {

    }
    private static volatile SPUtils instance;
    public static SPUtils getInstance() {
        if (instance == null) {
            throw new RuntimeException("使用 SPUtils 要init");
        }
        return instance;
    }
    public static void init(Context context){
        instance = new SPUtils();
        instance.sp = context.getSharedPreferences("shop", Context.MODE_PRIVATE);
    }
    public void putString(String key, String value) {
        sp.edit().putString(key, value).apply();
    }
    public String getString(String key, String defValue) {
        return sp.getString(key, defValue);
    }
}
